package htmodels

import (
	"github.com/astaxie/beego/orm"
	"choujiang/models"
)
func HTUserCouponAdd(usercoupon *models.UserCoupon) error {
	o := orm.NewOrm()
	_, err := o.Insert(usercoupon)
	return err
}

func HTUserCouponGetDetail(usercoupon *models.UserCoupon) error {
	o := orm.NewOrm()
	return o.Read(usercoupon)
}

func HTUserCouponGetCount(search string, searchFiled string ) (int64, error) {
	o := orm.NewOrm()
	m := models.UserCoupon{}
	count, err := o.QueryTable(m.TableName()).Filter(searchFiled + "__icontains", search).Count()
	return count, err
}

func HTUserCouponGetList(usercoupons *[]models.UserCoupon, fields []string , offset int64, limit int, search string, searchFiled string, orderby string) error {
	o := orm.NewOrm()
	m := models.UserCoupon{}
	_, err := o.QueryTable(m.TableName()).Filter(searchFiled + "__icontains", search).OrderBy(orderby).Offset(offset).Limit(limit).All(usercoupons, fields...)
	return err
}

func HTUserCouponDelete(Ids []int64) (int64, error) {
	o := orm.NewOrm()
	m := models.UserCoupon{}
	count, err := o.QueryTable(m.TableName()).Filter("Id" + "__in", Ids).Delete()
	return count, err
}
func HTUserCouponUpdate(usercoupon *models.UserCoupon) error {
	o := orm.NewOrm()
	_, err := o.Update(usercoupon)
	return err
}